<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>测试</title>
    <script type="text/javascript" src="js/jquery-1.8.3.js"></script>
    <script type="text/javascript">
        $(function () {
            bindInfo();
            bindEvent()
        })
        function bindEvent(){
            $("#sid").live("click",function () {
                var id=$(this).attr("code");
                window.location="/com/zb/cn/toinfo?id="+id;
            })
            $("#35ddda").live("click",function () {
                window.location="/add.html"
            })
            $("#del").live("click",function () {
                var id=$(this).attr("code");
                $.ajax({
                    url:"/com/zb/cn/del",
                    type:"post",
                    dateType:"json",
                    data:{"id":id},
                    success:function (mes) {
                        var count=parseInt(mes);
                        if(count!=0){
                            alert("删除成功")
                            $("#info").html("");
                            bindInfo();
                        }else{
                           alert("删除失败")
                        }
                    }
                })
            })
        }
        function bindInfo(){
            $.ajax({
                url:"/com/zb/cn/listStudent",
                type:"post",
                dataType:"json",
                success:function (mes) {
                    var text="";
                    $(mes).each(function (i) {
                        var s=mes[i]
                        text+="<tr>"
                        text+="<td>"+s.id+"</td>"
                        text+="<td>"+s.name+"</td>"
                        text+="<td id='sid' code="+s.id+">查看</td>"
                        text+="<td id='del' code="+s.id+">删除</td>"
                        text+="</tr>"
                    })
                    $("#info").append(text);
                }
            })
        }
    </script>
</head>
<body>
    <div align="center">
        <table border="1" bordercolor="red">
            <thead>
                <tr>
                    <td>
                        编号
                    </td>
                    <td>
                        姓名
                    </td>
                    <td colspan="2">
                         操作
                    </td>
                </tr>
                <tr>
                    <td colspan="4" align="center" id="add">新增</td>
                </tr>
            </thead>
            <tbody id="info"></tbody>
        </table>
    </div>
</body>
</html>